﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RoadTeam.Standard;
using RoadTeam.Pub;
using System.Web.Script.Serialization;
using RoadTeam.BLL;
using System.Data;

public partial class 对接测试页面_CsMaintenance : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Maintenance_MainInfo MainInfo = new Maintenance_MainInfo();
        MainInfo.MaintenanceIdentities = String.Empty;
        MainInfo.MaintenanceCode = @"BJSample00000001";
        MainInfo.UnitIdentifier = @"49b6cf8525b94153a3cde2ac87d00629";
        MainInfo.MaintenanceAddress = @"写字楼/第1栋/第01层/101";
        MainInfo.MaintenanceDate = DateTime.Now.ToString();
        MainInfo.MaintenanceType = @"A";
        MainInfo.MaintenanceContent = @"维修灯泡什么的";
        MainInfo.MaintenanceContact = @"张三";
        MainInfo.MaintenanceContactPhone = @"0123456789";
        MainInfo.MaintenanceCreater = @"李四";
        MainInfo.OrganIdentifier = @"eb3df1a4cd7b415198b414a21e13fa58";
        MainInfo.MaintenanceRemark = @"这里是备注什么的";

        List<Maintenance_DetailInfo> li = new List<Maintenance_DetailInfo>();
        Maintenance_DetailInfo DetailInfo = new Maintenance_DetailInfo();
        DetailInfo.MainDetailIdentifier = String.Empty;
        DetailInfo.MainIdentifier = String.Empty;
        DetailInfo.OrganIdentifier = @"eb3df1a4cd7b415198b414a21e13fa58";
        DetailInfo.ProjectIdentitfier = @"6aeb867bb4ee4f878b0a1e1d992a098a";
        DetailInfo.CreateDateTime = DateTime.Now.ToString();
        li.Add(DetailInfo);

        DetailInfo = new Maintenance_DetailInfo();
        DetailInfo.MainDetailIdentifier = String.Empty;
        DetailInfo.MainIdentifier = String.Empty;
        DetailInfo.OrganIdentifier = @"eb3df1a4cd7b415198b414a21e13fa58";
        DetailInfo.ProjectIdentitfier = @"b286d5c7a5454c008a6fb0d41a95dd1c";
        DetailInfo.CreateDateTime = DateTime.Now.ToString();
        li.Add(DetailInfo);

        Maintenance maintenance = new Maintenance();
        List<Maintenance> li1 = new List<Maintenance>();
        maintenance.DetailInfo = li.ToArray();
        maintenance.MainInfo = MainInfo;
        li1.Add(maintenance);

        CsMaintenance csmaintenance = new CsMaintenance();
        csmaintenance.Item = li1.ToArray();

        JavaScriptSerializer jvs = new JavaScriptSerializer();
        TextBox1.Text = jvs.Serialize(csmaintenance);
    }


    protected void Button3_Click(object sender, EventArgs e)
    {
        String Json = TextBox1.Text;
        JavaScriptSerializer jvs = new JavaScriptSerializer();
        CsMaintenance main = jvs.Deserialize<CsMaintenance>(Json);

        CsMaintenanceBll Main_bll = new CsMaintenanceBll();
        CsMaintenanceDetailBll Detail_bll = new CsMaintenanceDetailBll();
        DataTable Table_MainInfo = Main_bll.GetEmptyTable();
        DataRow dr_MainInfo;
        DataTable Table_DetailInfo = Detail_bll.GetEmptyTable();
        DataRow dr_DetailInfo;
        String Str = String.Empty;
        String DetailIdentifier = String.Empty;
        foreach (Maintenance item in main.Item)
        {
            Str = RoadTeam.Pub.CreateIdentifier.GetIdentifier();
            dr_MainInfo = Table_MainInfo.NewRow();
            dr_MainInfo["MaintenanceAddress"] = item.MainInfo.MaintenanceAddress;
            dr_MainInfo["MaintenanceCode"] = item.MainInfo.MaintenanceCode;
            dr_MainInfo["MaintenanceContact"] = item.MainInfo.MaintenanceContact;
            dr_MainInfo["MaintenanceContactPhone"] = item.MainInfo.MaintenanceContactPhone;
            dr_MainInfo["MaintenanceContent"] = item.MainInfo.MaintenanceContent;
            dr_MainInfo["MaintenanceCreater"] = item.MainInfo.MaintenanceCreater;
            dr_MainInfo["MaintenanceDate"] = item.MainInfo.MaintenanceDate;
            dr_MainInfo["MaintenanceIdentities"] = Str;
            item.MainInfo.MaintenanceIdentities = Str;
            dr_MainInfo["MaintenanceRemark"] = item.MainInfo.MaintenanceRemark;
            dr_MainInfo["MaintenanceType"] = item.MainInfo.MaintenanceType;
            dr_MainInfo["OrganIdentifier"] = item.MainInfo.OrganIdentifier;
            dr_MainInfo["UnitIdentifier"] = item.MainInfo.UnitIdentifier;
            Table_MainInfo.Rows.Add(dr_MainInfo);

            foreach (Maintenance_DetailInfo detail in item.DetailInfo)
            {
                DetailIdentifier = RoadTeam.Pub.CreateIdentifier.GetIdentifier();
                dr_DetailInfo = Table_DetailInfo.NewRow();
                dr_DetailInfo["CreateDateTime"] = detail.CreateDateTime;
                dr_DetailInfo["MainDetailIdentifier"] = DetailIdentifier;
                detail.MainDetailIdentifier = DetailIdentifier;
                dr_DetailInfo["MainIdentifier"] = Str;
                detail.MainIdentifier = Str;
                dr_DetailInfo["OrganIdentifier"] = detail.OrganIdentifier;
                dr_DetailInfo["ProjectIdentitfier"] = detail.ProjectIdentitfier;
                Table_DetailInfo.Rows.Add(dr_DetailInfo);
            }
        }
        Main_bll.InSertMaintenance(Table_MainInfo);

        Detail_bll.InsertMaintenanceDetail(Table_MainInfo, Table_DetailInfo);

    }
}